package net.edu_soft.ec.asset.controller;


import net.edu_soft.ec.asset.pojo.School;
import net.edu_soft.ec.asset.service.SchoolService;
import net.edu_soft.ec.common.annotation.SysLogInfo;
import net.edu_soft.ec.common.util.ResultVo;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 *  @author: PUING
 *  @Date: 2020/4/20 20:03
 *  @Description: 高校控制器
 */
@RestController
@RequestMapping(value = "/school")
public class SchoolController {

    @Autowired
    private SchoolService schoolService;

    /***
     * 查询单个高校信息
     * @param schoolId 高校id
     * @return 高校信息
     */
    @RequestMapping(value = "/find")
    @RequiresPermissions("school:find")
    public ResultVo find(Integer schoolId){

        return ResultVo.succeed("根据id查找高校信息",schoolService.find(schoolId));
    }

    /***
     * 分页模糊查询
     * @param name 高校名
     * @param pageNum 当前页
     * @param pageSize 每页数
     * @return 高校信息
     */
    @RequestMapping(value = "/findList")
    @RequiresPermissions("school:findList")
    public ResultVo  findList(String name, Integer pageNum, Integer pageSize){

        return  ResultVo.succeed("根分页查询",schoolService.findList(name,pageNum,pageSize));
    }

    /***
     * 添加高校信息
     * @param name 高校名
     * @param logo 高校logo
     * @return
     */
    @SysLogInfo(value = "添加高校信息")
    @RequestMapping(value = "/save")
    @RequiresPermissions("school:save")
    public ResultVo  save(String name,String logo){
        String m = 1==schoolService.save(name,logo)?"成功添加":"添加失败";
        return  ResultVo.succeed(m,null);
    }

    /***
     * 修改高校信息
     * @param school 高校信息
     * @return
     */
    @SysLogInfo(value = "修改高校信息")
    @RequestMapping(value = "/update")
    @RequiresPermissions("school:update")
    public ResultVo update(School school){

        String m = 1==schoolService.update(school)?"成功修改":"修改失败";
        return  ResultVo.succeed(m,null);
    }

    /***
     * 批量删除高校信息
     * @param ids id串
     * @param isDel 是否删除 1删除
     * @return
     */
    @SysLogInfo(value = "删除高校信息")
    @RequestMapping(value = "/del")
    @RequiresPermissions("school:del")
    public ResultVo  del(String ids,Integer isDel){

        String m = 1==schoolService.del(ids,isDel)?"成功删除":"删除失败";
        return  ResultVo.succeed(m,null);
    }

}
